package cn.tianwt.proxy;

import cn.tianwt.proxy.http.server.HttpProxyServer;
import cn.tianwt.proxy.http.utils.LogUtils;

public class Application  implements Context {

	HttpProxyServer mHttpProxyServer;
	
	private int port = 1080;
	long timeout  = 30*1000;
	

	@Override
	public void onCreated() throws Exception {
		LogUtils.D("Server-onCreated");
		mHttpProxyServer = new HttpProxyServer(this);
		mHttpProxyServer.start();
		
	}
	
	@Override
	public void onStart() throws Exception {
			LogUtils.D("Server-onStart");
			if(mHttpProxyServer==null) return;
			mHttpProxyServer.run();
	}

	@Override
	public void onPause() throws Exception {
			LogUtils.D("Server-onPause");
			if(mHttpProxyServer==null) return;
			mHttpProxyServer.pause();
		
	}


	@Override
	public void onDestory() throws Exception {
			LogUtils.D("Server-onDestory");
			if(mHttpProxyServer==null) return;
			mHttpProxyServer.destory();
		
	}

	@Override
	public boolean isReady() {
		if(mHttpProxyServer==null) return false;
		return mHttpProxyServer!=null && mHttpProxyServer.isReay();
	}

	@Override
	public boolean isRunning() {
		if(mHttpProxyServer==null) return false;
		return mHttpProxyServer!=null&& mHttpProxyServer.isRunning();
	}

	public void setTimeout(long timeout) {
		this.timeout = timeout;
	}
	
	public void setPort(int port) {
		this.port = port;
	}
	
	public int getPort() {
		return port;
	}

	public long getTimeout() {
		return timeout;
	}

	@Override
	public boolean isPaused() {
		return mHttpProxyServer!=null && mHttpProxyServer.isPaused();
	}
	
}
